import axios from "axios";

export default {
  state: {
    allSchools: [],
  },
  getters: {},
  mutations: {},
  actions: {
    selectSchoolsByCid(context, data) {
      let url = "/school/select/by/cid";
      let postData = {
        cid: data.cid,
      };
      let config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      axios
        .post(url, postData, config)
        .then((resp) => data.success(resp))
        .catch((resp) => data.error(resp));
    },
    getAllSchool(context, data) {
      let url = "/school/get/all";
      let postData = {};
      let config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      axios
        .post(url, postData, config)
        .then((resp) => {
          context.state.allSchools = resp.data.data;
          data.success(context.state.allSchools);
        })
        .catch((resp) => data.error(resp));
    },
    addNewSchool(context, data) {
      let url = "/school/add";
      let postData = data.school;
      let config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      axios
        .post(url, postData, config)
        .then((resp) => {
          data.success(resp);
        })
        .catch((resp) => {
          data.error(resp);
        });
    },
    updateSchool(context, data) {
      let url = "/school/update";
      let postData = data.school;
      let config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      axios
        .post(url, postData, config)
        .then((resp) => {
          data.success(resp);
        })
        .catch((resp) => {
          data.error(resp);
        });
    },
    deleteSchoolById(context, data) {
      let url = "/school/delete/by/id";
      let postData = {
        id: data.id,
      };
      let config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      axios
        .post(url, postData, config)
        .then((resp) => {
          data.success(resp);
        })
        .catch((resp) => {
          data.error(resp);
        });
    },
  },
  modules: {},
};
